const baseUrl = 'https://www.xiongmaoyouxuan.com'

const request = options => {
  const { url, method = 'GET', data, header } = options
  return new Promise((resolve,reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header: {
        ...header,
        token: 'adshasdguaigdbasjk'
      },
      success: resData => {
        if(resData.statusCode >= 200 && resData.statusCode < 300){
          const {code,data} = resData.data
          if(code===200){
            resolve(data)
          }
        }
        const err = new Error('接口访问异常')
        err.error = resData
        reject(err)
      },
      fail: err => reject(err),
    })
  })
}

module.exports = request